
package com.jf.cloud.api.delivery.feign;

import com.jf.cloud.api.delivery.dto.CalculateAndGetDeliverInfoDTO;
import com.jf.cloud.api.delivery.dto.ChangeOrderAddrDTO;
import com.jf.cloud.api.delivery.dto.DeliveryOrderDTO;
import com.jf.cloud.api.delivery.vo.DeliveryCompanyExcelVO;
import com.jf.cloud.api.delivery.vo.DeliveryOrderFeignVO;
import com.jf.cloud.api.delivery.vo.ShopTransportVO;
import com.jf.cloud.api.delivery.vo.StationVO;
import com.jf.cloud.common.feign.FeignInsideAuthConfig;
import com.jf.cloud.common.order.vo.UserDeliveryInfoVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @author zz
 * @date 2020/12/14
 */
@FeignClient(value = "jfcloud-delivery",contextId ="delivery")
public interface DeliveryFeignClient {

    /**
     * 计算运费，并计算获取配送信息
     * @param param 用户地址和订单信息
     * @return void
     */
    @PostMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/calculateAndGetDeliverInfo")
    ServerResponseEntity<UserDeliveryInfoVO> calculateAndGetDeliverInfo(@RequestBody CalculateAndGetDeliverInfoDTO param);

	/**
	 * 根据订单号获取包裹信息
	 * @param orderId 订单id
	 * @throws UnsupportedEncodingException 编码异常
	 * @return 包裹信息
	 */
	@GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/getByDeliveryByOrderId")
	ServerResponseEntity<List<DeliveryOrderFeignVO>> getByDeliveryByOrderId(@RequestParam("orderId") Long orderId);

    /**
     * 生成物流信息及保存物流与订单关联
     * @param deliveryOrderDTO 订单发货信息
     * @return void
     */
    @PostMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/saveDeliveryInfo")
    ServerResponseEntity<Void> saveDeliveryInfo(@RequestBody DeliveryOrderDTO deliveryOrderDTO);

    /**
     * 获取店铺运费模板列表
     * @param shopId 店铺id
     * @return 运费模板列表
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/listTransportByShopId")
    ServerResponseEntity<List<ShopTransportVO>> listTransportByShopId(@RequestParam("shopId") Long shopId);

    /**
     * 根据id列表获取运费模板
     * @param transportIds
     * @return
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/listTransportByIds")
    ServerResponseEntity<List<ShopTransportVO>> listTransportByIds(@RequestBody List<Long> transportIds);

    /**
     * 获取物流公司名称
     * @return 物流公司名称
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/listDeliveryCompany")
    ServerResponseEntity<List<DeliveryCompanyExcelVO>> listDeliveryCompany();

    /**
     * 计算订单修改地址后的运费更改价格
     * @param orderAddrDTO
     * @return
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/getOrderChangeAddrAmount")
    ServerResponseEntity<Double> getOrderChangeAddrAmount(@RequestBody ChangeOrderAddrDTO orderAddrDTO);

    /**
     * 根据订单号列表获取发货数量
     * @param orderIds
     * @return
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/delivery/listDeliveryCountByOrderIds")
    ServerResponseEntity<List<DeliveryOrderFeignVO>> listDeliveryCountByOrderIds(@RequestBody List<Long> orderIds);

    /**
     * 判断用户地址是否包含在配送范围内
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/insider/delivery/checkAddr")
    ServerResponseEntity<Boolean> checkAddr(@RequestParam("deliveryTemplateId") Long deliveryTemplateId, @RequestParam("userId")Long userId, @RequestParam("addrId")Long addrId);

    /**
     * 检查配送范围
     * @param deliveryTemplateId 运费模板id
     * @param addrId 用户地址id
     * @return
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/insider/delivery/checkDeliveryRange")
    ServerResponseEntity<Boolean> checkDeliveryRange(@RequestParam(name = "deliveryTemplateId", required = false) Long deliveryTemplateId,
                                                     @RequestParam("addrId") Long addrId);

    /**
     * 根据自提点id获取自提门店详情
     */
    @GetMapping(value = FeignInsideAuthConfig.FEIGN_URL_PREFIX + "/insider/delivery/getStationInfoById")
    ServerResponseEntity<StationVO> getStationInfoById(@RequestParam("stationId") Long stationId);


}
